﻿using Microsoft.Practices.Unity;
using Microsoft.Practices.Unity.InterceptionExtension;
using MotorLibrary.DAL;
using MotorLibrary.Repository;
using MotorLibrary.Repository.Converter;
using MotorLibrary.Service;
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using WebMotor.Controllers;

namespace WebMotor
{
    public class UnityContainerFactory
    {
        public UnityContainer GetInstance()
        {
            UnityContainer container = new UnityContainer();
            
            container.AddNewExtension<Interception>();
            Interceptor interceptor = new Interceptor(new InterfaceInterceptor());
            InterceptionBehavior interceptionBehavior = new InterceptionBehavior(new MiInterceptionBehavior());

  
            container.RegisterType<ITipoController, TipoController>();
            container.RegisterType<ITipoService, TipoService>(interceptor, interceptionBehavior);
            container.RegisterType<ITipoRepository, TipoRepository>(interceptor, interceptionBehavior);
            container.RegisterType<ITipoConverter, TipoConverter>();

            container.RegisterType<IEndpointController, EndpointController>();
            container.RegisterType<IEndpointService, EndpointService>(interceptor, interceptionBehavior);
            container.RegisterType<IEndpointRepository, EndpointRepository>(interceptor, interceptionBehavior);
            container.RegisterType<IEndpointConverter, EndpointConverter>();

            container.RegisterType<IEjecucionController, EjecucionController>();
            container.RegisterType<IEjecucionService, EjecucionService>(interceptor, interceptionBehavior);
            container.RegisterType<IEjecucionRepository, EjecucionRepository>(interceptor, interceptionBehavior);
            container.RegisterType<IEjecucionConverter, EjecucionConverter>();

            container.RegisterType<IVariableController, VariableController>();
            container.RegisterType<IVariableService, VariableService>(interceptor, interceptionBehavior);
            container.RegisterType<IVariableRepository, VariableRepository>(interceptor, interceptionBehavior);
            container.RegisterType<IVariableConverter, VariableConverter>();

            container.RegisterType<IVariableEjecucionController, VariableEjecucionController>();
            container.RegisterType<IVariableEjecucionService, VariableEjecucionService>(interceptor, interceptionBehavior);
            container.RegisterType<IVariableEjecucionRepository, VariableEjecucionRepository>(interceptor, interceptionBehavior);
            container.RegisterType<IVariableEjecucionConverter, VariableEjecucionConverter>();

            container.RegisterType<IMotorDbContextFactory, MotorDbContextFactory>();
            container.RegisterType<IDatabaseInitializer<MotorDbContext>, MotorDbInitializer>();

            container.RegisterType<IDescargadorFactory, DescargadorFactory>();

            return container;
        }
    }
}